<?php
namespace Home\Controller;
use Lib\Controller\HomeBaseController;
use Think\Upload;

//首页-控制器
class ServerController extends HomeBaseController {
    
    private $ordersModel;
    private $washLogModel;
    private $serverModel; 
    private $ServerAdminModel;
    private $serverAddressModel;
    public function __construct(){
        $this->ordersModel = D('Order');
        $this->washLogModel = D('washLog');
        $this->serverModel = D('server');
        $this->ServerAdminModel = D('ServerAdmin');
        $this->serverAddressModel = D('serverAddress');
//         $arr = array('id'=>1,'p_id'=>0,'is_shopowner'=>1);
//         session('userinfo',$arr);
        parent::__construct();
    } 
    /**
     * 注册服务端后选择继续选择角色
     */
    public function select_role(){
        $this->display();
    }
    /**
     * 員工選擇店鋪頁面
     */
    public function select_shop(){
        $userinfo = cookie('userinfo');
        if($userinfo['p_id']==0 && $userinfo['is_shopowner']==1 && $userinfo['is_staff']==0){
            redirect(U(MODULE_NAME.'/server/server_order_list'));
        }
        else if($userinfo['p_id']!=0 && $userinfo['is_shopowner']==0 && $userinfo['is_staff']==0){
            redirect(U(MODULE_NAME.'/server/staff_wait',array('type'=>'staff')));
        }
        else{
            $serverWhere['p_id'] = 0;
            $serverWhere['is_shopowner'] = 1;
            $serverList = $this->serverModel->where($serverWhere)->select();
            $this->assign('list',$serverList);
            $this->display();
        }
    }
    /**
     * 审核中页面
     */
    public function staff_wait($type){
        $this->assign('type',$type);
        
        $this->display('staff_wait');
    }
    /**
     * 选择成为店长还是店员
     */
    public function update_server_info(){
        $type = I('type');
        $userinfo = cookie('userinfo');
        if($type == 'shopowner'){
            if($userinfo['p_id']!=0 &&$ $userinfo['is_shopowner']==0 && $userinfo['is_staff']==0){
                redirect(U(MODULE_NAME.'/server/staff_wait',array('type'=>'shopowner')));
            }else{
                $updateServerData['p_id'] = 0;
                $updateServerData['is_shopowner'] = -1;
                $this->serverModel->where('id = '.cookie('userinfo')['id'])->save($updateServerData);
                //替換新的值
                $serverNewInfo = cookie('userinfo');
                $serverNewInfo['p_id'] = $updateServerData['p_id'];
                $serverNewInfo['is_shopowner'] = $updateServerData['is_shopowner'];
                //存入新的緩存
                session('userinfo',null);cookie('userinfo',null);
                session('userinfo',$serverNewInfo);cookie('userinfo',$serverNewInfo);
                redirect(U(MODULE_NAME.'/server/index'));
            }
        }
        else if($type == 'staff'){
            $checkApply = $this->serverModel->where('id = '.cookie('userinfo')['id'])->find();
            if($checkApply['p_id']!=0){
                $returndata['status'] = 0;
                $returndata['info'] = '您已提交過申請，請耐心等待！';
                $returndata['url'] = U(MODULE_NAME.'/server/staff_wait',array('type'=>'staff'));
                $this->ajaxReturn($returndata);
            }else{
                $updateServerData['p_id'] = I('get.serverId');
                $updateServerData['is_staff'] = 0;
                $this->serverModel->where('id = '.cookie('userinfo')['id'])->save($updateServerData);
                //替換新的值
                $serverNewInfo = cookie('userinfo');
                $serverNewInfo['p_id'] = $updateServerData['p_id'];
                $serverNewInfo['is_staff'] = $updateServerData['is_staff'];
                //存入新的緩存
                session('userinfo',null);cookie('userinfo',null);
                session('userinfo',$serverNewInfo);cookie('userinfo',$serverNewInfo);
                
                $returndata['status'] = 1;
                $returndata['info'] = '申請成功';
                $returndata['url'] = U(MODULE_NAME.'/server/staff_wait',array('type'=>'staff'));
                $this->ajaxReturn($returndata);
            }
        }
    }
    
    /**
     * 通過session判斷用戶是是店鋪端還是員工端
     */
    public function index(){
        if(session('userinfo')['p_id']==0 && session('userinfo')['is_shopowner']==1){
            $this->server_order_list();
        }
        else if(session('userinfo')['p_id']!=0 && session('userinfo')['is_staff']==1){
            $this->washer_order_list();
        }
        else if(session('userinfo')['p_id']!=0 && session('userinfo')['is_staff']==0){
            $this->staff_wait('staff');
        }
        else if(session('userinfo')['p_id']==0 && session('userinfo')['is_shopowner']==-1){
            $this->staff_wait('shopowner');
        }
        else{
            $this->staff_wait('staff');
        }
    }
    /**
     * 店鋪端的訂單列表
     */ 
    public function server_order_list(){
        $type = I('get.type');
        $todayStr = date('Y-m-d', time());
        $todayOP = strtotime($todayStr);
        $where['server_id'] = session('userinfo')['id'];
        if($type=='' || $type=='today'){
            $where['_string'] = 'o.end_time > '.time();
        }
        else if($type=='timeout'){
            $where['_string'] = 'o.end_time < '.time();
        }
        else if($type=='book'){
            $where['_string'] = 'o.book_time > '.time();
        }
        $orderList = $this->ordersModel->find_order($where);
//         p($this->ordersModel->getLastSql());
        foreach($orderList as$key =>$val){
            $checkLogWhere['ordersn'] = $val['ordersn'];
            $logInfo = $this->washLogModel->where($checkLogWhere)->order('id desc')->find();
            if($val['card_type']!=1){
                if($logInfo['create_time']>$todayOP && $logInfo['create_time']<$todayOP+86400){
                    $orderList[$key]['is_select'] = 1;//已安排
                }else if($logInfo['create_time']<$todayOP){
                    $orderList[$key]['is_select'] = 0;//未安排
                }else if($logInfo['start_time']!='' && $logInfo['end_time']!=''){
                    $orderList[$key]['is_select'] = 2;//已完成
                }
            }else{
                if($logInfo['start_time']!='' && $logInfo['end_time']==''){
                    $orderList[$key]['is_select'] = 1;//已安排且已開始
                }else if($logInfo['start_time']!='' && $logInfo['end_time']!=''){
                    $orderList[$key]['is_select'] = 2;//已完成
                }else{
                    $orderList[$key]['is_select'] = 0;//未安排
                }
            }
        }
//         p($orderList);
        $orderNum = $this->calculation_order_num($todayOP);
        $this->assign('orderNum',$orderNum);
        $this->assign('list',$orderList);
        $this->display('server_index');
    }
    /**
     * 員工端訂單列表
     */
    public function washer_order_list(){
        $serverOrderWhere['server_id'] = session('userinfo')['p_id'];
        $serverOrderWhere['wash_status'] = 1;
        $serverOrderList = $this->ordersModel->field('ordersn')->where($serverOrderWhere)->order('id desc')->select();
        $washLogOrdersn = '';
        foreach($serverOrderList as$key =>$val){
            $washLogWhere['ordersn'] = $val['ordersn'];
            $washLogResult = $this->washLogModel->where($washLogWhere)->order('id desc')->find();
            $checkWashId = explode(',', $washLogResult['server_id']);
            foreach($checkWashId as $key2 =>$val2){
                if($val2 == session('userinfo')['id']){
                    $washLogOrdersn = $val['ordersn'] .','.$washLogOrdersn;
                }
            }
        }
        $washLogOrdersn = rtrim($washLogOrdersn,',');
        $washLogOrdersn = explode(',', $washLogOrdersn);
        $orderList = array();
        foreach($washLogOrdersn as$k => $v){
            $where['o.ordersn'] = $v;
            $order = $this->ordersModel->find_order($where);
            $orderList = array_merge($orderList,$order);
        }
        foreach($orderList as$o=>$l){
            $se = explode('-', $l['book_time']);
            $orderList[$o]['book_start'] = date('Y-m-d',time()).' '.$se[0];
            $orderList[$o]['book_end'] = date('Y-m-d',time()).' '.$se[1];
            $orderList[$o]['wash_log'] = $this->washLogModel->where('ordersn = '.$v)->order('id desc')->find();
        }
        $this->assign('list',$orderList);
        $this->display('washer_index');
    }
    
    /**
     * 计算订单数量
     * @param unknown $time
     * @return number
     */
    public function calculation_order_num($time){
        $where['server_id'] = session('userinfo')['id'];
        $where['_string'] = 'end_time > '.time();
        $orderNum['today'] = count($orderList = $this->ordersModel->find_order($where));
        
        $where['_string'] = 'end_time < '.time();
        $orderNum['before'] = count($orderList = $this->ordersModel->find_order($where));
        
        $where['_string'] = 'book_time > '.time();
        $orderNum['after'] = count($orderList = $this->ordersModel->find_order($where));
        
        return $orderNum;
    }
    /**
     * 店鋪端與員工端公用的訂單詳情頁
     */
    public function server_order_info(){
        $where['o.ordersn'] = I('ordersn');
        $orderList = $this->ordersModel->find_order($where);
        foreach($orderList as $key=>$val){
            $orderInfo = $orderList[$key];
            $se = explode('-', $val['book_time']);
            $orderInfo['book_start'] = date('Y-m-d',time()).' '.$se[0];
            $orderInfo['book_end'] = date('Y-m-d',time()).' '.$se[1];
            $orderInfo['server_address'] = $this->serverAddressModel->where('id ='.$val['server_address_id'])->find();
            $orderInfo['wash_log'] = $this->washLogModel->where('ordersn ='.$val['ordersn'])->order('id desc')->find();
        }
        $serverId = $orderInfo['wash_log']['server_id']; 
        $serverIdArr = explode(',', $serverId);
        $serverName = '';
        foreach($serverIdArr as $key2 =>$val2){
            $serverNameWhere['id'] = $val2;
            $serverNameResult = $this->serverModel->field('name')->where($serverNameWhere)->find();
            $serverName = $serverName.','.$serverNameResult['name'];
        }
        $orderInfo['wash_log']['server_name'] = ltrim($serverName, ",");
        $this->assign('info',$orderInfo);
        $this->assign('userInfo',cookie('userinfo'));
//         p($orderInfo);
//         p(cookie('userinfo'));
        $this->display();
    }
    /**
     * 店鋪端選擇洗車員工
     */
    public function dispatch_wash(){
        $where['p_id'] = session('userinfo')['id'];
        $serverMan = D('server')->where($where)->select();
//         p($serverMan);
        $this->assign('staffList',$serverMan);
        $this->display();
    }
    /**
     * 員工上傳洗車的頁面
     */
    public function upload_car_info(){
        $todayStr = date('Y-m-d', time());
        $todayOP = strtotime($todayStr);
        
        $where['ordersn'] = I('get.ordersn');
        $orderinfo = $this->washLogModel->where($where)->order('id desc')->find();
        if($orderinfo['create_time'] >$todayOP){
            $orderinfo['is_today'] = 1;
        }else{
            $orderinfo['is_today'] = 0;
        }
//         p($orderinfo);
//         $wxCheckInternetStatus = new WxBusinessAutorizerInfoLogic();
        
//         $noncestr = random_string('alnum', 16);
//         $timestamp = time();
//         $url = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
//         $jsapiTicket = $authorizerJSAPITicket;
//         $signature = $wxBusinessAutorizerInfoLogic->sha1JSAPI($jsapiTicket, $noncestr, $timestamp, $url);
        $this->assign('info',$orderinfo);
        $this->assign('user',cookie('userinfo'));
        $this->display();
    }
    /**
     * 上傳員工洗車的車輛信息
     */
    public function upload_wash_info(){
        $where['ordersn'] = I('post.ordersn');
        $data['car_remark'] = I('post.car_remarks');
        
        $config = array(
            'maxSize' => 0, //上传的文件大小限制 (0-不做限制)
            'exts' => array('jpg', 'gif', 'png', 'jpeg'),// 设置附件上传类型
            'subName' => array('date', 'Ymd'), //子目录创建方式，[0]-函数名，[1]-参数，多个参数使用数组
            'saveName'   =>    array('uniqid',''),
            'savePath' => C('UPLOAD_CAR_IMG_PATH'), //保存路径
            'rootPath' => './Upload/',
            'autoSub'    =>    true,
        );
        $this->uploader = new Upload($config, 'Local');
        $info = $this->uploader->upload($_FILES);
        if(!$info){//提示错误信息
            $returndata ['status'] = 0; // 状态
            $returndata ['info'] = $this->uploader->getError();
            $this->ajaxReturn($returndata);
        }else{
            $num = 0;
            foreach($info as$x =>$val){
                $num++;
                if($num==1){
                    $data['carhead_img'] = $val['savepath'] . $val['savename'];
                }
                else if($num == 2){
                    $data['carleft_img'] = $val['savepath'] . $val['savename'];
                }
                else if($num == 3){
                    $data['carright_img'] = $val['savepath'] . $val['savename'];
                }
                else if($num == 4){
                    $data['carback_img'] = $val['savepath'] . $val['savename'];
                }
                $data['upload_img_time'] = time();
                $data['start_time'] = time();
            }
            $uploadResult = $this->washLogModel->where($where)->order('id desc')->save($data);
            $neworderData['wash_status'] = '1';
            $this->ordersModel->where($where)->save($neworderData);
            if($uploadResult!==false){
                
                $returndata['status'] = 1;
                $returndata['info'] = '確認成功';
                $returndata['url'] = U(MODULE_NAME.'/server/upload_car_info',array('ordersn'=>$where['ordersn']));
                $this->ajaxReturn($returndata);
            }else{
                $returndata['status'] = 0;
                $returndata['info'] = '確認失敗';
                $this->ajaxReturn($returndata);
            }
        }
    }
    /**
     * 員工點擊結束洗車任務
     */
    public function end_wash(){
        $where['o.ordersn'] = I('post.ordersn');
        $orderInfo = $this->ordersModel->find_order($where,$check='find');
        if($orderInfo['card_type'] == 1){
            $orderData['wash_status'] = 2;
            $orderData['finish_time'] = time();
        }
        else{
            if($orderInfo['end_time']>time()){
                $orderData['wash_status'] = 0;//當結束時間大於當前時間則歸零
            }
            else if($orderInfo['end_time'] > strtotime(date('Y-m-d', time())) && $orderInfo['end_time'] < strtotime(date('Y-m-d', time()))+86400){
                $orderData['wash_status'] = 2;//當結束時間在今天則修改為完成
                $orderData['finish_time'] = time();
            }
        }
        $washLogData['end_time'] = time();
        
        $updateWashWhere['id'] = I('post.orderId');
        $updateOrderWhere['ordersn'] = I('post.ordersn');
        $washLogUpdate = $this->washLogModel->where($updateWashWhere)->order('id desc')->save($washLogData);
        $orderUpdate = $this->ordersModel->where($updateOrderWhere)->save($orderData);
        if($washLogUpdate !==false && $orderUpdate!==false){
            if($orderInfo['card_type']==1){
                $cardType = '次卡';
            }
            else if($orderInfo['card_type']==2){
                $cardType = '周卡';
            }
            else if($orderInfo['card_type']==3){
                $cardType = '月卡';
            }
            else if($orderInfo['card_type']==4){
                $cardType = '年卡';
            }
            
            $washLogoInfo = $this->washLogModel->where($updateWashWhere)->find();
            
            $pdata=array(
                'first'=>array(
                    'value'=>urlencode("洗車提示"),
                    "color"=>"#000000"
                ),
                'keyword1'=>array(
                    'value'=>$cardType,
                    'color'=>"#FF0000"
                ),
                'keyword2'=>array(
                    'value'=>$orderInfo['license_plate'],
                    'color'=>"#000000"
                ),
                'keyword3'=>array(
                    'value'=>date('Y-m-d H:i',$washLogoInfo['start_time']),
                    'color'=>"#000000"
                ),
                'keyword4'=>array(
                    'value'=>date('Y-m-d H:i',time()),
                    'color'=>"#000000"
                ),
                'remark'=>array(
                    'value'=>"洗車完成",
                    'color'=>"#FF8800"
                ),
            );
            
            $template_id = "vyXT33XkXU5sFVZRWUyC8U-6FPkjMaOOx4EoqhrTfos";
            
            $this->pushWXMessage($orderInfo, $pdata ,$template_id);
            
            
            $returndata['status'] = 1;
            $returndata['info'] = '完成任務！';
            $returndata['url'] = U(MODULE_NAME.'/server/washer_order_list',array('type'=>'today'));
            $this->ajaxReturn($returndata);
        }else{
            $returndata['status'] = 0;
            $returndata['info'] = '系統出錯！';
            $this->ajaxReturn($returndata);
        }
    }
    /**
     * 上傳選擇的員工
     */
    public function select_washer(){
        $todayStr = date('Y-m-d', time());
        $todayOP = strtotime($todayStr);
        
        $where['ordersn'] = $ordersn = I('post.ordersn');
        $data['server_id'] = I('post.s_id');
        $data['create_time'] = time();
        $newdata['wash_status'] = 1;
        
        $checkWashLog = $this->washLogModel->where($where)->order('id desc')->find();
        $washLogWhere['id'] = $checkWashLog['id'];
        if($checkWashLog['create_time']==''){
            $result = $this->washLogModel->where($washLogWhere)->save($data);
        }
        elseif ($checkWashLog['create_time'] !='' && $checkWashLog['create_time'] < $todayOP ){
            $data['ordersn'] = I('post.ordersn');
            $result = $this->washLogModel->add($data);
        }
        
        
        $orderResult = $this->ordersModel->where($where)->save($newdata);
        if($result !== false && $orderResult !== false){
            $nWhere['o.ordersn'] = $ordersn;
            $checkOrder = $this->ordersModel->find_order($nWhere,'find');
            $checkWashLog = $this->washLogModel->where($where)->order('id desc')->find();
            
            $pdata=array(
                'first'=>array(
                    'value'=>urlencode("您有個新訂單"),
                    "color"=>"#000000"
                ),
                'keyword1'=>array(
                    'value'=>$ordersn,
                    'color'=>"#FF0000"
                ),
                'keyword2'=>array(
                    'value'=>date('Y-m-d H:i',$checkWashLog['create_time']),
                    'color'=>"#000000"
                ),
                'keyword3'=>array(
                    'value'=>urlencode($checkOrder['wash_address']),
                    'color'=>"#000000"
                ),
                'keyword4'=>array(
                    'value'=>urlencode($checkOrder['license_plate'].' '.$checkOrder['color'].' '.$checkOrder['brand']),
                    'color'=>"#000000"
                ),
                'keyword5'=>array(
                    'value'=>urlencode($checkOrder['order_phone']),
                    'color'=>"#000000"
                ),
                'remark'=>array(
                    'value'=>urlencode("請盡快洗車"),
                    'color'=>"#FF8800"
                ),
            );
            $template_id = "CsdqNH202qJftUhZ9Cupxj3RsSe53obCNlKWMiApr38";
            $serverIdList = explode(',', $checkWashLog['server_id']);
            foreach(I('post.s_id') as $s => $v){
                $serverInfo = $this->serverModel->where('id = '.$v)->find();
                $this->pushWXMessage($serverInfo, $pdata ,$template_id);
            }
            
            $returndata['status'] = 1;
            $returndata['info'] = '選擇成功!';
            $returndata['url'] = U(MODULE_NAME.'/server/server_order_list',array('type'=>'today'));
            $this->ajaxReturn($returndata);
        }else{
            $returndata['status'] = 0;
            $returndata['info'] = '選擇失敗!';
            $this->ajaxReturn($returndata);
        }
    }
    /**
     * 店铺端的个人中心
     */
    public function set_index(){
        
        $joinList = count($this->serverModel->get_wait_join_staff());
        if(session('userinfo')['is_shopowner']==1){
            $this->assign('role','shopowner');
        }else{
            $this->assign('role','staff');
        }
        $this->assign('count',$joinList);
        $this->display('my');
    }
    /**
     * 添加卡的价格
     */
    public function add_card_price(){
        if(IS_GET){
            $where['id'] = session('userinfo')['id'];
            $serverInfo = $this->serverModel->where($where)->find();
            $this->assign('info',$serverInfo);
            $this->display();
        }
        else if(IS_POST){
            $newdata['day_card'] = I('post.day');
            $newdata['day_seven_card'] = I('post.day_seven');
            $newdata['day_other_card'] = I('post.day_other');
            $newdata['week_card'] = I('post.week');
            $newdata['week_seven_card'] = I('post.week_seven');
            $newdata['week_other_card'] = I('post.week_other');
            $newdata['month_card'] = I('post.month');
            $newdata['month_seven_card'] = I('post.month_seven');
            $newdata['month_other_card'] = I('post.month_other');
            $newdata['year_card'] = I('post.year');
            $newdata['year_seven_card'] = I('post.year_seven');
            $newdata['year_other_card'] = I('post.year_other');
            $where['id'] = session('userinfo')['id'];
            $result = $this->serverModel->where($where)->save($newdata);
            if($result!==false){
                $returndata['status'] = 1;
                $returndata['info'] = '設置成功！';
                $returndata['url'] = U(MODULE_NAME.'/server/set_index');
                $this->ajaxReturn($returndata);
            }else{
                $returndata['status'] = 0;
                $returndata['info'] = '設置失敗！';
                $this->ajaxReturn($returndata);
            }
        }
    }
    /**
     * 录入店铺信息
     */
    public function set_shop_info(){
        if(IS_GET){
            $where['id'] = session('userinfo')['id'];
            $serverInfo = $this->serverModel->where($where)->find();
            if($serverInfo['shop_img']!=''){
                $serverInfo['avatar'] = $serverInfo['shop_img'];
            }else{
                $serverInfo['avatar'] = $serverInfo['weixin_avatar'];
            }
            $this->assign('info',$serverInfo);
            $this->display();
        }
        else if(IS_POST){
            $where['id'] = session('userinfo')['id'];
            
            $data['phone'] = I('post.phone');
            $data['name'] = I('post.shopname');
            $data['server_start_time'] = I('post.server_start_time');
            $data['server_end_time'] = I('post.server_end_time');
            $data['tips'] = I('post.tips');
            $data['address'] = I('post.address');
            //地理編碼把地址轉換成經緯度
            $getData = 'http://restapi.amap.com/v3/geocode/geo?key=9cd137305f879d522cc8049535fb196d&address='.$data['address'];
            $getResultJson = file_get_contents($getData);
            $getResult = json_decode($getResultJson,true);
            $geocode = explode(',', $getResult['geocodes'][0]['location']);
            
            $data['lon'] = $geocode[0];
            $data['lat'] = $geocode[1];
            if($_FILES['upload_avatar']['name']){
                $config = array(
                    'maxSize' => 0, //上传的文件大小限制 (0-不做限制)
                    'exts' => array('jpg', 'gif', 'png', 'jpeg'),// 设置附件上传类型
                    'subName' => array('date', 'Ymd'), //子目录创建方式，[0]-函数名，[1]-参数，多个参数使用数组
                    'saveName'   =>    array('uniqid',''),
                    'savePath' => 'server_img/', //保存路径
                    'rootPath' => './Upload/',
                    'autoSub'    =>    true,
                );
                $this->uploader = new Upload($config, 'Local');
                $info = $this->uploader->upload($_FILES);
                
                if(!$info){//提示错误信息
                    $returndata ['status'] = 0; // 状态
                    $returndata ['info'] = $this->uploader->getError();
                    $this->ajaxReturn($returndata);
                }else{
                    foreach($info as$x =>$val){
                        $data['shop_img'] = './Upload/'.$val['savepath'] . $val['savename'];
                    }
                    $image = new \Think\Image();
                    $image->open('./Upload/'.$data['shop_img']);
                    // 生成一个居中裁剪为150*150的缩略图并保存为thumb.jpg
                    $image->thumb(260, 260,\Think\Image::IMAGE_THUMB_CENTER)->save('./Upload/'.$data['shop_img']);
                }
            }
            
            $updateShopInfo = $this->serverModel->where($where)->save($data);  
            if($updateShopInfo !== false){
                $returndata['status'] = 1;
                $returndata['info'] = '設置成功！';
                $returndata['url'] = U(MODULE_NAME.'/server/set_index');
                $this->ajaxReturn($returndata);
            }else{
                $returndata['status'] = 0;
                $returndata['info'] = '設置失敗！';
                $this->ajaxReturn($returndata);
            }
        }
    }
    /**
     * 店长审核申请加入的人
     */
    public function  washer_audit(){
        $joinList = $this->serverModel->get_wait_join_staff();
        foreach($joinList as$key=>$val){
            $joinList[$key]['weixin_avatar'] = substr($val['weixin_avatar'],0,strlen($val['weixin_avatar'])-1);
            $joinList[$key]['weixin_avatar'] = $val['weixin_avatar'].'64';
        }
        $this->assign('list',$joinList);
        $this->display();
    }
    /**
     * 修改申請人員的狀態
     * type delete為刪除申請 success為通過成功
     */
    public function change_washer_status(){
        $type = I('post.type');
        if($type == 'delete'){
            $where['id'] = I('post.washerId');
            $data['p_id'] = 0;
            $data['is_shopowner'] = 0;
            $data['is_staff'] = 0;
            $changeResult = $this->serverModel->where($where)->save($data);
            if($changeResult!==false){
                $returndata['status'] = 1;
                $returndata['info'] = '刪除成功！';
                $this->ajaxReturn($returndata);
            }else{
                $returndata['status'] = 0;
                $returndata['info'] = '刪除失敗！';
                $this->ajaxReturn($returndata);
            }
        }
        else if($type == 'success'){
            $where['id'] = I('post.washerId');
            $data['is_shopowner'] = 0;
            $data['is_staff'] = 1;
            $changeResult = $this->serverModel->where($where)->save($data);
            if($changeResult!==false){
                $returndata['status'] = 1;
                $returndata['info'] = '確認成功！';
                $this->ajaxReturn($returndata);
            }else{
                $returndata['status'] = 0;
                $returndata['info'] = '確認失敗！';
                $this->ajaxReturn($returndata);
            }
        }
    }
    /**
     * 我的員工列表
     */
    public function staff_list(){
        $staffList = $this->serverModel->get_wait_join_staff($is_staff='1');
        $this->assign('list',$staffList);
        $this->display();
    }
    /**
     * 设置后台账户信息
     */
    public function set_server_admin(){
        if(IS_GET){
            $where['server_id'] = session('userinfo')['id'];
            $serverInfo = $this->ServerAdminModel->where($where)->find();
            $this->assign('info',$serverInfo);
            $this->display();
        }
        if(IS_POST){
            $where['server_id'] = session('userinfo')['id'];
            
            $data['admin_password'] = md5(I('post.password'));
            
            $updateShopInfo = $this->ServerAdminModel->where($where)->save($data);
            if($updateShopInfo !== false){
                $returndata['status'] = 1;
                $returndata['info'] = '設置成功！';
                $returndata['url'] = U(MODULE_NAME.'/server/set_index');
                $this->ajaxReturn($returndata);
            }else{
                $returndata['status'] = 0;
                $returndata['info'] = '設置失敗！';
                $this->ajaxReturn($returndata);
            }
        }
    }
}